package media.process;

import gui.panels.jtree.filesystem.FileSystemCategoryInfo;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.UUID;

import conf.PropReaderWriter;

public class MediaSliceContainer implements Transferable, Serializable {
	
	private File mediaSource;
	private File mediaTempCut;
	private Long startTime;
	private Long stopTime;
	
	final public static DataFlavor INFO_FLAVOR =
		new DataFlavor(MediaSliceContainer.class, "MediaSliceContainer");

	static DataFlavor flavors[] = {INFO_FLAVOR };
	
	public MediaSliceContainer(File source, Long start, Long stop){
		setMediaSource(source);
		setStartTime(start);
		setStopTime(stop);
		String tempCutName = this.calculateTmpFileName();
		mediaTempCut = new File(tempCutName);
		
	}

	private String calculateTmpFileName() {
		// TODO Auto-generated method stub
		String tempDir = PropReaderWriter.getProperty("temp_dir");
		String mediaFileExtension = PropReaderWriter.getProperty("media_file_extension");
		UUID id = UUID.randomUUID();
		String filename = id.toString();
		
		return tempDir+File.separatorChar+filename+mediaFileExtension;
	}

	public File getMediaTempCut(){
		return mediaTempCut;
	}
	public File getMediaSource() {
		return mediaSource;
	}

	public void setMediaSource(File mediaSource) {
		this.mediaSource = mediaSource;
	}

	public Long getStartTime() {
		return startTime;
	}

	public void setStartTime(Long startTime) {
		this.startTime = startTime;
	}

	public Long getStopTime() {
		return stopTime;
	}

	public void setStopTime(Long stopTime) {
		this.stopTime = stopTime;
	}

	@Override
	public Object getTransferData(DataFlavor arg0)
			throws UnsupportedFlavorException, IOException {
		if (arg0.equals(INFO_FLAVOR)) {
			return this;
		}
		else throw new UnsupportedFlavorException(arg0);
	}

	@Override
	public DataFlavor[] getTransferDataFlavors() {
	
		return MediaSliceContainer.flavors;
	}

	@Override
	public boolean isDataFlavorSupported(DataFlavor arg0) {
		return arg0.equals(INFO_FLAVOR);
	}

	public Transferable getUserObject() {
		
		return this;
	}
	
	
	

}
